package com.bum.api.processor.dev.json;

import org.apache.commons.lang.StringUtils;

import com.bum.api.core.exp.om.Metas;
import com.bum.api.core.exp.om.Params;
import com.bum.api.core.service.process.ApiProcess;
import com.bum.api.processor.dev.json.bo.DevJsonBO;

public class DevJsonProcess extends ApiProcess {
	DevJsonBO	devJsonBO;

	enum Func {
		base64Encode,
		base64Decode,
		urlEncode,
		urlDecode
	}

	@Override
	public String process(String path, Params params, Metas metas) {
		String[] parts = StringUtils.split(path, "/", 3);

		Func func = null;
		if (parts.length >= 2) {
			func = Func.valueOf(parts[1]);
			switch (func) {
				case base64Decode:
					return devJsonBO.base64Decode(null, params, metas);

				case base64Encode:
					return devJsonBO.base64Encode(null, params, metas);

				case urlEncode:
					return devJsonBO.urlEncode(null, params, metas);

				case urlDecode:
					return devJsonBO.urlDecode(null, params, metas);

				default:
					break;
			}
		}

		return null;
	}

	public void setDevJsonBO(DevJsonBO devJsonBO) {
		this.devJsonBO = devJsonBO;
	}

}
